<!DOCTYPE html>
<!-- ng-app -->
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="../../../js/plugins/angular/angular.min.js" type="text/javascript"></script>
</head>
<body>
    <div ng-controller="cont">
        <!-- 视图组件 -->
    </div>

    <script>
        /* 自己定义的服务 $custom */
        var app = angular.module('app',[])
            .factory('$custom',function () {
                return {
                    print:function (msg) {
                        console.log(msg);
                    }
                };
            });
        var injector = angular.injector(['app','ng']);
        /* 判断有没有$custom这个服务 */
        var has = injector.has('$custom');
        console.log(has);
        if(has){
            /* get方法获取指定服务名称的实例对象 */
            var custom = injector.get('$custom');
            custom.print("控制台输出任意的内容");
        }
        app.controller('cont',['$scope','$custom',function ($scope,$custom) {
            // 控制代码
        }])

    </script>
</body>
</html>